<script>

export default {
  name: 'CategoryEdit',
  data () {
    return {
      show: false,
      formData: {
        categoryId: '',
        name: '',
        profile: '',
        status: 1
      },
      rules: {
        name: [{ required: true, message: '请输入分类名称' }]
      }
    }
  },
  methods: {
    init (id) {
      this.show = true
      this.formData = { ...this.$options.data().formData }
      if (id) {
        this.$axios.get(`category/info/${id}`).then(data => {
          this.formData = { ...data }
        })
      }
    },
    submit () {
      this.$refs.dataFormRef.validate(valid => {
        if (valid) {
          this.$axios.post('category/update', this.formData).then(() => {
            this.$message.success('操作成功！')
            this.show = false
            this.$emit('close')
          }).catch(e => e)
        }
      })
    }
  }
}
</script>

<template>
<el-dialog title="分类信息" :visible.sync="show" v-if="show">
  <el-form ref="dataFormRef" :model="formData" :rules="rules" label-width="80px">
    <el-form-item label="分类名" prop="name">
      <el-input v-model="formData.name" placeholder="请输入分类名"/>
    </el-form-item>
    <el-form-item label="分类说明">
      <el-input v-model="formData.profile" placeholder="请输入分类说明" type="textarea" maxlength="120" show-word-limit/>
    </el-form-item>
    <el-form-item label="状态">
      <el-radio-group v-model="formData.status">
        <el-radio :label="1">可用</el-radio>
        <el-radio :label="2">禁用</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item>
      <el-button @click="submit">提交</el-button>
    </el-form-item>
  </el-form>
</el-dialog>
</template>

<style scoped lang="scss">

</style>
